import 'package:flutter/material.dart';

class DemoBottomNavigationBar extends StatefulWidget {
  int currentIndex;
  final ValueChanged<int> onTap;

  DemoBottomNavigationBar({Key? key, required this.currentIndex,required this.onTap}) : super(key: key);
  @override
  State<StatefulWidget> createState() {
    return _BottomNavigationBarState();
  }

}

class _BottomNavigationBarState extends State<DemoBottomNavigationBar> {
  int _currentIndex = 0;
  @override
  void initState() {
    super.initState();
    _currentIndex = widget.currentIndex;
     print("build ${_currentIndex}");
  }

  void _onTapHandler(int index){
    _currentIndex = index;
    widget.onTap(_currentIndex);
  }

  @override
  Widget build(BuildContext context) {
    return BottomNavigationBar(
          currentIndex: _currentIndex,
          type: BottomNavigationBarType.fixed,
          fixedColor: Colors.black,
          items:  const [
            BottomNavigationBarItem(icon: Icon(Icons.explore), label:'Explore'),
            BottomNavigationBarItem(icon: Icon(Icons.history), label: 'History'),
            BottomNavigationBarItem(icon: Icon(Icons.list), label: 'List'),
            BottomNavigationBarItem(icon: Icon(Icons.person), label: 'My'),
          ],
          onTap: _onTapHandler,
        );
  }
}